/**
 * 每个Ai的范围在[1, Ri]
 * 求所有的A，满足总和是K的倍数
 * 按字典序输出
 * 规模很小，暴力枚举
 * 一共 8^5 。
 */
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

using llt = long long;
using vi = vector<int>;
using vll = vector<llt>;
using pii = pair<int, int>;
using pll = pair<llt, llt>;

int N, K;
vi R;
vi Out;
int S;

void dfs(int depth){
    if(depth == N){
        if(0 == S % K){
            for(auto i : Out) cout << i << " ";
            cout << "\n";
        }
        return;
    }

    for(int i=1;i<=R[depth];++i){
        Out[depth] = i;
        S += i;
        dfs(depth + 1);
        S -= i;
    }
    return;
}

void proc(){
    Out.assign(N, S = 0);
    dfs(0);
    return;
}

void work(){
    cin >> N >> K;
    R.assign(N, {});
    for(auto & i : R) cin >> i;
    proc();
    return;
}


int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);	
    int nofkase = 1;
	// cin >> nofkase;
	while(nofkase--) work();
	return 0;
}